package com.yanqu.road.server.cmd.assistant;

import com.yanqu.road.pb.assistant.AssistantProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.assistant.AssistantModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/11/11 9:54
 */
@Cmd(code = GameProtocol.S_ASSISTANT_SHOP_SET, desc = "小助理商店设置")
public class AssistantShopSetCmd extends AbstractCommand {
    private int mallId;
    private long count;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        AssistantProto.AssistantShopSetReqMsg msg = AssistantProto.AssistantShopSetReqMsg.parseFrom(packet.getBytes());
        mallId = msg.getMallId();
        count = msg.getCount();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(AssistantModule.class).setAssistantGoodsPreBuy(mallId, count);
    }

    @Override
    public void sendData(GamePlayer player) {
        AssistantProto.AssistantShopSetRespMsg.Builder respMsg = AssistantProto.AssistantShopSetRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_ASSISTANT_SHOP_SET, respMsg);
    }
}
